import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meiyunapp/entity/near_bystore_entity.dart';
import 'package:meiyunapp/page/collection/home_collection.dart';
import 'package:meiyunapp/widget/goods_widget.dart';

///首页底部的热门推荐
class HotStoreGoodsComponent extends GetView<HomeCollection> {
  const HotStoreGoodsComponent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      child: controller.obx(
        (data) => Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: data!.map((e) => body(e)).toList(),
        ),
        onLoading: const CupertinoActivityIndicator(),
        onEmpty: const Text("onEmpty"),
      ),
    );
  }

  Widget body(NearBystoreList entity) {
    List<Widget> data = List.empty(growable: true);
    List<NearBystoreListProducts> list = entity.products;

    if (list.isNotEmpty) {
      data.add(
        Container(
          margin: const EdgeInsets.only(left: 10),
          padding: const EdgeInsets.only(top: 10),
          alignment: Alignment.centerLeft,
          child: Text(
            entity.name,
            style: const TextStyle(fontSize: 16),
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
        ),
      );

      for (var element in list) {
        data.add(GoodsWidget(element));
      }
    }
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: data,
    );
  }
}
